<template>
  <div class="section-wrap" style="height:100%;margin-top: 40px;">
      <!-- 头部 -->
      <div class="headerBox">
        <div class="header">
          <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>
          违章统计
        </div>
      </div>
      <vue-better-scroll
      class="wrapper"
      ref="scrollqq"
      :scrollbar="scrollbarObj"
      :pullDownRefresh="pullDownRefreshObj"
      :pullUpLoad="pullUpLoadObj"
      :startY='parseInt(startY)'
      @pullingUp="onPullingUp"
    > 
      <div class="form-section">
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>选择单位</label>
          </div>
          <div class="input_div">
            <input type="text"
                   v-model="params.checkDepartName"
                   :disabled="isDisabled"/>
            <input type="hidden" v-model="params.CheckDepartId"/>
            <x-icon type="ios-arrow-right" size="22" class="icon-right" @click="getCompany(0)"></x-icon>
          </div>
        </div>
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>统计开始时间</label>
          </div>
          <group>
            <datetime v-model="startDate" format="YYYY-MM-DD" clear-text="清除" @on-clear="clearStartDate"></datetime>
          </group>
        </div>
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>统计结束时间</label>
          </div>
          <group>
            <datetime v-model="endDate" clear-text="清除" @on-clear="clearEndDate"></datetime>
          </group>
        </div>
       <p class="search-btn" @click="search">查询</p>
        <div class="info_div2">
          <div class="form-item">
            <div><span style="font-size: 16px;margin-right: 28px;">问题总数：36 个</span></div>
          </div>
        </div>
        <div class="project_div">
          <ul class="project_list">
            <li>
              <div class="project_text">
                <p>云南省质量技术监督综合技术检验检查基地</p>
                <span style="margin-right: 48px">违章次数：10</span>
              </div>
              <x-icon type="ios-arrow-right" size="24" class="icon-right"></x-icon>
            </li>
          </ul>
        </div>
      </div>
    </vue-better-scroll>
    <!--classValue 显示隐藏   data树结构  nodeClicK节点点击返回值  name显示的字段  -->
    <div v-transfer-dom>
      <popup v-model="classValue" width="100%">
        <select-depart @nodeClick='selectedDepart'></select-depart>
      </popup>
    </div>
  </div>

</template>
<script>
  import selectDepart from "@commonComponents/selectDepart/selectDepart";
  import formatDate from "../../utils/formatDate";
  import VueBetterScroll from "vue2-better-scroll"
  import {
    XHeader,
    Tabbar,
    TabbarItem,
    Group,
    Cell,
    TransferDom,
    Popup
  } from "vux";

  export default {
    directives: {
      TransferDom
    },
    data() {
      return {
        isjifen: [],
        accopt1: [['已整改', '待整改']],
        /*下拉刷新*/
        resultlist: [],
        scrollbarObj: {fade: true},
        pullDownRefreshObj: false,
        pullUpLoadObj: {
          threshold: 0,
          txt: {
            more: "加载更多",
            noMore: "没有更多数据了"
          }
        },
        startY: 0,
        scrollToX: 0,
        scrollToY: 0,
        scrollToTime: 700,
        url: "/api/services/app/Assessment/GetPageList",
        isDisabled: true, // 是否禁止输入
        totalCount: 0, //量化考试
        accpentlist: [],
        classValue: false,
        data: [],
        params: {
          id: [],
          planId: "",
          startDate: "",
          endDate: "",
          checkDepartId: "",
          beCheckDepartId: "",
          skipCount: 0,
          maxResultCount: 10
        },
        startDate: '',
        endDate: '',
        selectDepartType: 0
      };
    },
    components: {
      selectDepart,
      Popup,
      VueBetterScroll
    },
    created() {
    //   this.search();
    //   this.getData();
    },
    mounted(){
        let that = this;
        this.$bridge.registerHandler("setToken", function(data) {
                         that.$store.state.Authorization =
          "Bearer " + data;
            //这里data ioS返回的是token值(字符串)
            // that.search();
            // that.getData();
        });

        this.connectWebViewJavascriptBridge(function(bridge) {
            bridge.init(function(message, responseCallback) {});

            bridge.registerHandler("setToken", function(data) {
                             that.$store.state.Authorization =
          "Bearer " + data;
            // that.search();
            // that.getData();
                  //这里data android返回的是token值(字符串)

            });
        });
    },
    methods: {
      connectWebViewJavascriptBridge(callback) {
            if (window.WebViewJavascriptBridge) {
                callback(WebViewJavascriptBridge);
            } else {
                document.addEventListener(
                "WebViewJavascriptBridgeReady",
                function() {
                    callback(WebViewJavascriptBridge);
                },
                false
                );
            }
        },
      search() {
        if (this.startDate) {
          this.params.startDate = this.startDate + " 00:00:00";
        }
        if (this.endDate) {
          this.params.endDate = this.endDate + " 00:00:00";
        }
        this.params.skipCount = 0;
        this.$axiosAjax.GetPageListAssessment(this.params).then(res => {
          this.totalCount = res.data.result.totalCount;
          this.accpentlist = res.data.result.items;
        });
      },
      getData() {
        if (this.startDate) {
          this.params.startDate = this.startDate + " 00:00:00";
        }
        if (this.endDate) {
          this.params.endDate = this.endDate + " 00:00:00";
        }
        this.$axiosAjax.GetPageListAssessment(this.params).then(res => {

          this.totalCount = res.data.result.totalCount;
          // this.accpentlist = res.data.result.items;

          let relist = res.data.result.items;
          this.accpentlist = this.accpentlist.concat(relist);
          let totalAllCount = res.data.result.totalCount;
          let resultCount = this.accpentlist.length;
          if (parseInt(resultCount) < parseInt(totalAllCount)) {
            this.$refs['scrollqq'].forceUpdate(true);
          } else {
            this.$refs['scrollqq'].forceUpdate(false);
          }
        });
      },
      goBack() {
        this.$router.go(-1);
      },
      getCompany(type) {
        this.classValue = true;
        this.selectDepartType = type;
      },
      nodeClick(item) {
        if (
          item.departType == 6 ||
          item.departType == 7 ||
          item.departType == 8
        ) {
          this.detailData.DeptName = item.departName;
          this.params.checkDepartId = item.id;
          this.classValue = false;
        } else {
          this.$vux.toast.text("只能选择项目部");
        }
      },
      getTableTypeList() {
        this.$axiosAjax
          .getTableTypeList(this.params)
          .then(res => {
            if (res.data.result.isSuccess == true) {
              this.tableType = res.data.result.data;
            }
          })
          .catch(err => {
          });
      },
      selectedDepart(data) {
        if (this.selectDepartType == 0) {
          this.params.checkDepartId = data.id;
          this.params.checkDepartName = data.departName;
        } else {
          this.params.beCheckDepartId = data.id;
          this.params.beCheckDepartName = data.departName;
        }
        this.classValue = false;
      },
      clearStartDate() {
        this.startDate = "";
      },
      clearEndDate() {
        this.endDate = "";
      },
      onPullingUp() {

        let limitcount = this.accpentlist.length;
        this.params.skipCount = limitcount;
        // if (this.params.skipCount + this.params.maxResultCount < this.totalCount) {
        //   this.params.skipCount = this.params.skipCount + this.params.maxResultCount;
        this.getData();
        // }
      },
      onPullingDown() {
        this.search();
      }
    }
  };
</script>
<style lang="less" scoped>
  .search-btn {
    width: 200px;
    line-height: 36px;
    border-radius: 20px;
    margin: 23px auto;
    color: #fff;
    background: #469b7a;
    text-align: center;
    font-size:16px;
    letter-spacing: 4px;
  }

  .form-item {
    .input_div {
      .vux-x-icon {
        fill: #999;
        float: right;
        margin-top: 18px;
      }

    }
  }

  .project_div {
    .project_list {
      box-sizing: border-box;
      padding-left: 10px;
      li {
        border-bottom: 1px solid #efeff4;
        height: 80px;
        position: relative;
        span{
          padding-left: 10px;
        }
        p{
          padding-left: 10px;
          color: #333333;
          margin-bottom: 12px;
          font-size: 13px;
          font-weight: bold;
          overflow: hidden;
          text-overflow:ellipsis;
          white-space: nowrap;
          width: 66%;
        }
        span{
          color: #b7b7b7;
          font-size: 13px;
        }
        .icon-right [deep] {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
        }
        .project_text {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
        }
        .project_text {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }
        .project_status {
          margin-top: 14px;
          strong {
            font-size: 12px;
          }

          strong.project_status1 {
            color: #ff7333;
          }

          strong.project_status2 {
            color: #469b7a;
          }

        }

        .vux-x-icon {
          fill: #999;
          right: 20px;
          top: 50%;
          margin-top: -11px;
          position: absolute;
        }

      }
    }
  }

  .add_btn {
    position: fixed;
    height: 62px;
    width: 62px;
    right: 30px;
    bottom: 35px;
  }
</style>
